package com.zzyl.nursing.controller.member;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.zzyl.common.core.domain.R;
import com.zzyl.nursing.dto.ElderQueryDto;
import com.zzyl.nursing.dto.ReservationDto;
import com.zzyl.nursing.dto.UserLoginRequestDto;
import com.zzyl.nursing.vo.LoginVo;
import com.zzyl.nursing.vo.TimeCountVo;
import com.zzyl.serve.domain.NursingProject;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.apache.xmlbeans.impl.xb.xsdschema.TotalDigitsDocument;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.zzyl.common.annotation.Log;
import com.zzyl.common.core.controller.BaseController;
import com.zzyl.common.core.domain.AjaxResult;
import com.zzyl.common.enums.BusinessType;
import com.zzyl.nursing.domain.FamilyMember;
import com.zzyl.nursing.service.IFamilyMemberService;
import com.zzyl.common.utils.poi.ExcelUtil;
import com.zzyl.common.core.page.TableDataInfo;

/**
 * 老人家属Controller
 * 
 * @author laoYe
 * @date 2025-10-27
 */
@RestController
@RequestMapping("/member")
@Api(tags = "老人家属相关接口")
public class FamilyMemberController extends BaseController {
    @Autowired
    private IFamilyMemberService familyMemberService;




    @PostMapping("/user/login")
    @ApiOperation("小程序用户登录")
    public R login(@RequestBody UserLoginRequestDto dto){
        LoginVo vo=familyMemberService.login(dto);
        return R.ok(vo);
    }

    @GetMapping("/orders/project/page")
    @ApiOperation("分页查询护理项目列表")
    public TableDataInfo pageInfo( ElderQueryDto dto){
            TableDataInfo<NursingProject> tableDataInfo = familyMemberService.pageInfo(dto);
            return tableDataInfo;
    }

    @GetMapping("/orders/project/{id}")
    @ApiOperation("单个查询项目详细信息")
    public R<NursingProject> getInfo(@ApiParam(value = "项目ID", required = true)
            @PathVariable("id") Long id) {
        R<NursingProject> result= familyMemberService.getId(id);
        return result;
    }

    @GetMapping("/reservation/cancelled-count")
    @ApiOperation("查询取消预约数量")
    public R getCancelled(){
      Integer count= familyMemberService.cancelledCount();
        return R.ok(count);
    }

    @GetMapping("/reservation/countByTime")
    @ApiOperation("查询每个时间段剩余预约次数")
    public R<List<TimeCountVo>> countByTime(@RequestParam Long time) {
        List<TimeCountVo> result = familyMemberService.countByTime(time);
        return R.ok(result);
    }

    @PostMapping("/reservation")
    @ApiOperation("新增预约")
    public R addReservation(@RequestBody ReservationDto dto) {
        familyMemberService.addReservation(dto);
        return R.ok();
    }

    @GetMapping("/reservation/page")
    @ApiOperation("分页查询预约列表")
    public R pageReservation(ElderQueryDto dto){
       TableDataInfo<ReservationDto> tableDataInfo = familyMemberService.pageReservation(dto);
        return R.ok(tableDataInfo);
    }

    @PutMapping("/reservation/{id}/cancel")
    @ApiOperation("取消预约")
    public R cancelReservation(@PathVariable Long id){
        familyMemberService.cancelReservation(id);
        return R.ok();
    }





}
